package bdz.projects.sc.core
{
	
	/**
	 * ...
	 * @author ...
	 */
	public class SCUnit {
		public var name:String;
		protected var key:String;
		public var items:SCItemList;
		public var validSelections:Array;

		public function SCUnit(xm:XML):void {
			name = xm.@name;
			items = new SCItemList(xm.map.item);
			var cnt:Number = 0;
			validSelections = new Array();
			for each(var io:SCItemObject in items) {
				if (io.type != "nothing") {
					validSelections[cnt] = io;
					cnt++;
				}
				
			}
		}
		public function getRandomItem():SCItemObject {
			
			var rand:Number = Math.floor(Math.random() * validSelections.length);
			var randItem:SCItemObject = validSelections[rand];
			if (randItem.validSelections != null && randItem.validSelections.length > 0) {
				return randItem.getRandomSubset();
			}
			
			return randItem;
			
		}
		public function findItem(prop:String, key:String):SCItemObject {
			for each(var io:SCItemObject in validSelections) {
				if (io[prop] == key) {
					return io;
				}
			}
			return null;
		}
		public function set bind(k:String):void {
			key = k;
		}
		public function get bind():String {
			return key;
		}
	}
	
}